from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension

from sqlalchemy import Text

from sqlalchemy import Table, ForeignKey
from sqlalchemy.orm import relationship, backref

from scp.modelo.models import Base

association_table = Table('tipo_item_atributo', Base.metadata,
    Column('tipo_item_id', Integer, ForeignKey('tipo_item.id')),
    Column('atributo_id', Integer, ForeignKey('tipo_atributo.id'))
)

class Tipo_Item(Base):
    """ The SQLAlchemy declarative model class for a Tipo_Item object. """
    __tablename__ = 'tipo_item'
    id = Column(Integer, primary_key=True)
    nombre = Column(Text, nullable=False, unique=True)
    descripcion = Column(Text, nullable=False)
    observacion = Column(Text, nullable=True)
    atributos = relationship("Atributo",
                    secondary=association_table)
